#include "VertexBuffer.h"


VertexBuffer::VertexBuffer(void) : Resource()
{

}


VertexBuffer::~VertexBuffer(void)
{
	Dispose();
}

void VertexBuffer::Bind()
{
	if(IsAllocated() == false)
	{
		glGenBuffers(1,&buffer);
		SetAllocated();
	}

	glBindBuffer(GL_ARRAY_BUFFER,buffer);
}
void VertexBuffer::Dispose()
{
	Unbind();
	glDeleteBuffers(1,&buffer);
}

void VertexBuffer::Unbind()
{
	glBindBuffer(GL_ARRAY_BUFFER,0);
}

void VertexBuffer::BufferData(unsigned int lenght,void * data,Usage usage)
{
	if(usage == STATIC)
		glBufferData(GL_ARRAY_BUFFER,lenght,data,GL_STATIC_DRAW);
	else 
		glBufferData(GL_ARRAY_BUFFER,lenght,data,GL_DYNAMIC_DRAW);
}